//
// Created by yuping.li on 10/24/24.
//

#ifndef TIM_PWM_GENERATOR_HPP_
#define TIM_PWM_GENERATOR_HPP_

#include "tim.h"

class PwmGenerator {
 public:
  PwmGenerator(TIM_HandleTypeDef* timer, uint32_t channel) :
    m_timer(timer), m_channel(channel) { }


  HAL_StatusTypeDef init() {
    return HAL_TIM_PWM_Start(m_timer, m_channel);
  }

  void set_duty(uint32_t duty) {
    __HAL_TIM_SetCompare(m_timer, m_channel, duty);
  }

 protected:
  TIM_HandleTypeDef* m_timer{nullptr};
  uint32_t m_channel{0};
};

#endif //TIM_PWM_GENERATOR_HPP_
